﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;



namespace DotNetNuke.Tests.UI.WatiN.RegressionTests
{
    [TestFixture]

   public class FiveFourThreeTests : RTBase
    {

        #region Test Setup and TearDown

        public bool LanguagePackInstalled = false;

        [SetUp]
        public void SetUp()
        {

        }

        [TearDown]
        public void TearDown()
        {
            if (LanguagePackInstalled)
            {
                WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
                LoginPage loginPage = new LoginPage(homePage);
                if (!homePage.RegisterLink.Text.Contains(TestUsers.Host.DisplayName))
                {
                    if (!homePage.RegisterLink.Text.Equals("Register"))
                    {
                        loginPage.LogoffUser();

                    }
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                }
                //Uninstall the language pack and delete the files
                ieInstance.GoTo(SiteURL + "/Host/Extensions.aspx");
                ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
                extensionsPage.ExtensionPackageSelectList.Select("Core Language Pack");
                System.Threading.Thread.Sleep(2000);
                extensionsPage.GetExtensionUninstallButton(LocaleName).Click();
                System.Threading.Thread.Sleep(2000);
                extensionsPage.DeleteExtensionFilesCheckbox.Checked = true;
                ConfirmDialogHandler dialog = new ConfirmDialogHandler();
                using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
                {
                    extensionsPage.UninstallPackageLink.ClickNoWait();
                    dialog.WaitUntilExists();
                    dialog.OKButton.Click();
                }
                ieInstance.WaitForComplete();
                LanguagePackInstalled = false;
            }
            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        public void DNN_12333_Cannot_Create_Any_New_Image_Profile_Properties_On_Portals_over_0()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Act 
            ieInstance.GoTo(SiteURL + "/Host/Portals.aspx");
            HostPortalPage portalPage = new HostPortalPage(homePage);
            portalPage.AddChildPortal(ApplicationName, "Child Portal", "ChildPortal");
            ieInstance.GoTo(SiteURL + "/ChildPortal/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.ManageProfilePropertiesLink.Click();
            ProfilePropertiesPage propertiesPage = new ProfilePropertiesPage(homePage);
            propertiesPage.AddNewProfilePropertyLink.Click();

            //Add an Image property
            propertiesPage.PropertyNameField.Value = "TestImage";
            propertiesPage.DataTypeSelectList.Select("Image");
            propertiesPage.PropertyCategoryField.Value = "Test Properties";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert
            TableRow textPropertyRow = propertiesPage.GetPropertyRow("TestImage");
            Assert.IsTrue(textPropertyRow.Exists);
            Assert.IsTrue(textPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[1]));
            TableCell textVisibilityCell = propertiesPage.GetPropertyVisibilityCell(textPropertyRow);
            Assert.IsTrue(textVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            ieInstance.GoTo(SiteURL + "/ChildPortal/Admin/UserAccounts.aspx");
            userPage.GetUserEditButton(TestUsers.Admin2.DisplayName).Click();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.ManageProfileLink.Click();
            System.Threading.Thread.Sleep(2000);

            Span imageUploadSpan = ieInstance.Span(Find.ById(s => s.EndsWith("TestImageFileControl")));
            Assert.IsTrue(imageUploadSpan.Exists);

            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.GetUserEditButton(TestUsers.Admin.DisplayName).Click();
            profilePage.ManageProfileLink.Click();
            System.Threading.Thread.Sleep(2000);
            Assert.IsFalse(homePage.ContentPane.InnerHtml.Contains("TestImage"));
        }

        [Test]
        public void DNN_12341_Page_Hierarchy_On_Admin_Pages_Page()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            string pageName = "Test Page";

            //Add a new page
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.NewPageLink.Click();
            PageSettingsPage pageSettings = new PageSettingsPage(homePage);
            pageSettings.AddPage(pageName);
            System.Threading.Thread.Sleep(1500);

            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            ribbonBar.EditCurrentPageLink.Click();
            pageSettings.ParentPageSelection.Select("Home");
            pageSettings.AddPageLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("Home"));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains(pageName));
            ieInstance.GoTo(SiteURL + "/Admin/Pages.aspx");
            AdminPagesPage pagesPage = new AdminPagesPage(homePage);
            Assert.IsTrue(pagesPage.PagesSelectList.Option("..." + pageName).Exists);
            Assert.IsTrue(pagesPage.PagesSelectList.Option("Home").Index == 0);
            Assert.IsTrue(pagesPage.PagesSelectList.Option("..." + pageName).Index == 1);
        }

        [Test]
        public void DNN_12392_Telerik_LinkClick_Not_Supported()
        {
            //Arrange
            string pageName = "Test Page";
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
           
            //Act 
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.NewPageLink.Click();
            PageSettingsPage pageSettingsPage = new PageSettingsPage(homePage);
            pageSettingsPage.AddPageSelectTemplateAllUsersView(pageName, "Default");
            System.Threading.Thread.Sleep(1000);
            
            ModulePage module = new ModulePage(homePage);
            module.EditModuleContentLink.Click();
            System.Threading.Thread.Sleep(2500);
            HTMLModule htmlModule = new HTMLModule(homePage);
            //Add a link with link click enabled
            htmlModule.TelerikEditor.GetHyperLinkManagerLink("HTML").Click();
            Element item = htmlModule.TelerikEditor.GetPageSelectForHyperLink("rcbItem ", "Home");
            item.FireEvent("onmouseover");
            item.Click();
            htmlModule.TelerikEditor.HyperLinkTrackLinkCheckBox.Checked = true;
            htmlModule.TelerikEditor.HyperLinkTextField.Value = "TestLink";
            htmlModule.TelerikEditor.TelerikOKButton.Click();

            module.SaveContentLink.Click();

            //Log off
            loginPage.LogoffUser();
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            Link testLink = homePage.ContentPane.Link(Find.ByText("TestLink"));
            testLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbLink.Text.Equals("Home"));
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
            HostSQLPage sqlPage = new HostSQLPage(homePage);
            sqlPage.SQLQueryTextField.Value = "SELECT * FROM URLTRACKING";
            sqlPage.ExecuteSQLLink.Click();
            System.Threading.Thread.Sleep(1000);
            int linkClickValue = Convert.ToInt32(sqlPage.QueryResults.TableRows[1].TableCells[4].Text);
            Assert.IsTrue(linkClickValue > 0);
            Assert.IsTrue(sqlPage.QueryResults.TableRows[1].TableCells[8].CheckBox(Find.Any).Checked);
        }

        [Test]
        public void DNN_12422_Display_Module_On_All_Pages_Error()
        {
            //Arrange
            string pageName = "Test";
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
           
            //Act 
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.NewPageLink.Click();
            PageSettingsPage pageSettingsPage = new PageSettingsPage(homePage);
            pageSettingsPage.AddPageSelectTemplateAllUsersView(pageName, "Default");
            System.Threading.Thread.Sleep(1000);
            
            //Add another HTML Module
            string moduleName = "Test Module";
            string moduleContent = "This is test content";
            ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 1);
            
            //Make both modules display on all pages 
            HTMLModule htmlModule = new HTMLModule(homePage);
            htmlModule.GetModuleSettingsImage(0).Click();
            System.Threading.Thread.Sleep(1500);
            htmlModule.AdvancedSettingsExpandButton.Click();
            htmlModule.DisplayOnAllPagesCheckbox.Checked = true;
            htmlModule.UpdateLink.Click();
            System.Threading.Thread.Sleep(2500);

            htmlModule.GetModuleSettingsImage(1).Click();
            System.Threading.Thread.Sleep(1500);
            htmlModule.AdvancedSettingsExpandButton.Click();
            htmlModule.DisplayOnAllPagesCheckbox.Checked = true;
            htmlModule.UpdateLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            //Assert.IsFalse(homePage.PageContainsErrors());
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage(moduleName, moduleContent));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Enter Title"));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage("Enter Title", "Hover here, then click toolbar to edit content"));

            ieInstance.GoTo(SiteURL + "/UserProfile.aspx");
            //Assert.IsFalse(homePage.PageContainsErrors());
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage(moduleName, moduleContent));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Enter Title"));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage("Enter Title", "Hover here, then click toolbar to edit content"));

            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            //Assert.IsFalse(homePage.PageContainsErrors());
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage(moduleName, moduleContent));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Enter Title"));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage("Enter Title", "Hover here, then click toolbar to edit content"));

            ieInstance.GoTo(SiteURL + "/Admin/Languages.aspx");
            //Assert.IsFalse(homePage.PageContainsErrors());
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage(moduleName, moduleContent));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Enter Title"));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage("Enter Title", "Hover here, then click toolbar to edit content"));

            ieInstance.GoTo(SiteURL + "/Admin/SecurityRoles.aspx");
            //Assert.IsFalse(homePage.PageContainsErrors());
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage(moduleName, moduleContent));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Enter Title"));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage("Enter Title", "Hover here, then click toolbar to edit content"));

            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            //Assert.IsFalse(homePage.PageContainsErrors());
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage(moduleName, moduleContent));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Enter Title"));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage("Enter Title", "Hover here, then click toolbar to edit content"));

            ieInstance.GoTo(SiteURL + "/Admin/Pages.aspx");
            //Assert.IsFalse(homePage.PageContainsErrors());
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage(moduleName, moduleContent));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Enter Title"));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage("Enter Title", "Hover here, then click toolbar to edit content"));


            ieInstance.GoTo(SiteURL + "/Admin.aspx");
            //Assert.IsFalse(homePage.PageContainsErrors());
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage(moduleName, moduleContent));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Enter Title"));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage("Enter Title", "Hover here, then click toolbar to edit content"));

            ieInstance.GoTo(SiteURL + "/Admin/RecycleBin.aspx");
            //Assert.IsFalse(homePage.PageContainsErrors());
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage(moduleName, moduleContent));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Enter Title"));
            Assert.IsTrue(homePage.HtmlModuleExistsOnPage("Enter Title", "Hover here, then click toolbar to edit content"));

        }

        [Test]
        public void DNN_12428_Page_Management_Still_Broken_Case_1()
        {
            //Arrange
            string pageName = "Parent";
            string childName = "Child ";
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
           
            //Act
            //Add a parent Page
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.NewPageLink.Click();
            PageSettingsPage pageSettingsPage = new PageSettingsPage(homePage);
            pageSettingsPage.AddPage(pageName);

            //Add 5 Child Pages
            for(int i = 0; i < 5; i++)
            {
                System.Threading.Thread.Sleep(500);
                ribbonBar.NewPageLink.Click();
                System.Threading.Thread.Sleep(500);
                pageSettingsPage.AddChildPage((childName + i), pageName);
            }

            //Delete the third page
            ieInstance.GoTo(SiteURL + "/Admin/Pages.aspx");
            System.Threading.Thread.Sleep(5000);
            AdminPagesPage pagesPage = new AdminPagesPage(homePage);
            pagesPage.PagesSelectList.Select("...Child 2");
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();

            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                pagesPage.DeleteSelectedPageImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            ieInstance.WaitForComplete();
            System.Threading.Thread.Sleep(2000);

            //Move the fourth page
            int fourthPageInitialIndex = pagesPage.PagesSelectList.Option("...Child 3").Index;
            pagesPage.PagesSelectList.Select("...Child 3");
            pagesPage.MovePageUpButton.Click();
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(pagesPage.PagesSelectList.Option("...Child 1").Index > pagesPage.PagesSelectList.Option("...Child 3").Index);
            int offSet = fourthPageInitialIndex - pagesPage.PagesSelectList.Option("...Child 3").Index;
            Assert.IsTrue(offSet == 1);
            System.Threading.Thread.Sleep(1500);

            pagesPage.PagesSelectList.Select("...Child 3");
            pagesPage.MovePageDownButton.Click();
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(pagesPage.PagesSelectList.Option("...Child 1").Index < pagesPage.PagesSelectList.Option("...Child 3").Index);
            offSet = fourthPageInitialIndex - pagesPage.PagesSelectList.Option("...Child 3").Index;
            Assert.IsTrue(offSet == 0);
        }

        [Test]
        public void DNN_12428_Page_Management_Still_Broken_Case_2()
        {
            //Arrange
            string pageName = "Page ";
            string childName = "Child ";
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Act
            //Add 8 parent Pages
            RibbonBar ribbonBar = new RibbonBar(homePage);
            PageSettingsPage pageSettingsPage = new PageSettingsPage(homePage);
           
            for (int i = 0; i < 8; i++)
            {
                ribbonBar.NewPageLink.Click();
                System.Threading.Thread.Sleep(500);
                pageSettingsPage.AddPage(pageName + i);
            }
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            pageName = "Page 3";
            //Add 5 Child Pages to one of the pages
            for (int i = 0; i < 4; i++)
            {
                ribbonBar.NewPageLink.Click();
                System.Threading.Thread.Sleep(1500);
                pageSettingsPage.AddChildPage((childName + i), pageName);
            }

            ieInstance.GoTo(SiteURL + "/Admin/Pages.aspx");
            AdminPagesPage adminPages = new AdminPagesPage(homePage);

            //Assert that the pages were created correctly
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 0").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 1").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 3").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 0").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 1").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 2").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 3").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 4").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 5").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 6").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 7").Exists);

            //Try and move the pages
            //Move a page left
            adminPages.PagesSelectList.Select("...Child 3");
            adminPages.MovePageLeftButton.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(adminPages.PagesSelectList.Option("Child 3").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 3").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 0").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 1").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 2").Exists);

            //Move a page right
            adminPages.PagesSelectList.Select("...Child 2");
            adminPages.MovePageRightButton.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            //Assert
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 3").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 0").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 1").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("......Child 2").Exists);

            //Move the parent down
            adminPages.PagesSelectList.Select("Page 3");
            adminPages.MovePageDownButton.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            int page3Pos = adminPages.PagesSelectList.Option("Page 3").Index;
            int page4Pos = adminPages.PagesSelectList.Option("Page 4").Index;
            int child1Pos = adminPages.PagesSelectList.Option("...Child 1").Index;
            int child0Pos = adminPages.PagesSelectList.Option("...Child 0").Index;
            int child2Pos = adminPages.PagesSelectList.Option("......Child 2").Index;
            //Assert
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 4").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("Page 3").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 0").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 1").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("......Child 2").Exists);
            Assert.IsTrue(page4Pos < page3Pos);
            Assert.IsTrue((child0Pos - page3Pos) == 1);
            Assert.IsTrue((child1Pos - child0Pos) == 1);
            Assert.IsTrue((child2Pos - child1Pos) == 1);


            //Move a child up
            adminPages.PagesSelectList.Select("...Child 1");
            adminPages.MovePageUpButton.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            child1Pos = adminPages.PagesSelectList.Option("...Child 1").Index;
            child0Pos = adminPages.PagesSelectList.Option("...Child 0").Index;
            child2Pos = adminPages.PagesSelectList.Option("......Child 2").Index;
            //Assert
            Assert.IsTrue(adminPages.PagesSelectList.Option("...Child 1").Exists);
            Assert.IsTrue(adminPages.PagesSelectList.Option("......Child 2").Exists);
            Assert.IsTrue(child1Pos < child0Pos);
            Assert.IsTrue(child2Pos < child0Pos);
            Assert.IsTrue((child0Pos - child2Pos) == 1);
        }

        [Test]
        public void DNN_12563_Language_Module_Cant_Open_Resource_Strings_Edit()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/Languages.aspx");
            LanguagePage languagePage = new LanguagePage(homePage);
            languagePage.GetHostLanguageEditButton("English (United States)").ClickNoWait();

            //Assert
            Assert.IsTrue(languagePage.EditorModeHostRadioButton.Checked);
            Assert.IsTrue(languagePage.EditorLanguageLabel.InnerHtml.Contains("English (United States)"));
            Assert.IsFalse(languagePage.ErrorImage.Exists);

            ieInstance.GoTo(SiteURL + "/Admin/LogViewer.aspx");
            EventViewerPage eventViewer = new EventViewerPage(homePage);
            Assert.IsFalse(eventViewer.LogViewerTable.InnerHtml.Contains("General Exception"));
            Assert.IsFalse(eventViewer.LogViewerTable.InnerHtml.Contains("Page Load Exception"));
            Assert.IsFalse(eventViewer.LogViewerTable.InnerHtml.Contains("Module Load Exception"));
        }

        //[Test]
        //public void DNN_12574_Bulk_Extension_Installation_Requires_Version_Increment()
        //{
        //    //Arrange
        //    SetUpTestForInstall();
        //    RunAutoInstall();
        //    ieInstance.Close();
            
        //    //Act
        //    File.Copy(Path.Combine(TestFilesPath, "Events_05.00.02_Install.zip"), Path.Combine(PhysicalPath + "\\Install\\Module\\Events_05.00.02_Install.zip"));
        //    File.Copy(Path.Combine(TestFilesPath, "Events_05.00.03_Install.zip"), Path.Combine(PhysicalPath + "\\Install\\Module\\Events_05.00.03_Install.zip"));

        //    ieInstance = WatiNUtil.OpenIEInstance(SiteURL + "/install/install.aspx?mode=installresources", SilentMode, IETimeOut, AutoCloseIE, AutoMovePointer);
        //    WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);

        //    //Assert
        //    Assert.IsTrue(ieInstance.Text.Contains("Installing Package File Events_05.00.02_Install:  Success"));
        //    Assert.IsTrue(ieInstance.Text.Contains("Installing Package File Events_05.00.03_Install:  Success"));
        //    Assert.IsTrue(ieInstance.Text.Contains("Installing Optional Skins:"));
        //    Assert.IsTrue(ieInstance.Text.Contains(" Installing Optional Languages:"));
        //    Assert.IsTrue(ieInstance.Text.Contains("Installing Optional Packages"));
        //    Assert.IsTrue(ieInstance.Text.Contains("Installation Complete"));

        //    ieInstance.Link(Find.ByText("Click Here To Access Your Portal")).Click();
        //    LoginPage loginPage = new LoginPage(homePage);
        //    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

        //    ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
        //    ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
        //    extensionsPage.FilterByTypeSelectList.Select("Module");
        //    TableRow eventsModuleRow = extensionsPage.GetExtensionRow("Events");
        //    Assert.IsTrue(eventsModuleRow.Exists);
        //    Assert.IsTrue(eventsModuleRow.InnerHtml.Contains("5.0.3"));
        //}


        [Test]
        public void DNN_12657_Start_Stop_Buttons_Should_Not_Show_Under_View_Schedule_Status_When_Using_Request_Method()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Act
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.OtherSettingsExpandButton.ClickNoWait();
            hostSettings.SchedularModeSelectList.Select("Request Method");
            hostSettings.UpdateLink.ClickNoWait();

            System.Threading.Thread.Sleep(1500);
            ieInstance.GoTo(SiteURL + "/Host/Schedule.aspx");
            SchedulePage schedulePage = new SchedulePage(homePage);
            schedulePage.ViewScheduleStatusLink.Click();

            //Assert 
            Assert.IsFalse(schedulePage.CommandSpan.Exists);
            Assert.IsFalse(schedulePage.StartLink.Exists);
            Assert.IsFalse(schedulePage.StopLink.Exists);
        }


        [Test]
        public void DNN_12676_Add_Additional_Encoding_To_Sitelog()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add a user
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1500);
            
            //Act
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).Click();
            userPage.FirstNameField.Value = "<iframe src=";
            userPage.LastNameField.Value = "\"http://www.slashdot.org\"/>";
            userPage.UpdateLink.Click();
            System.Threading.Thread.Sleep(2500);

            //Assert
            ieInstance.GoTo(SiteURL + "/Admin/SiteLog.aspx");
            AdminSiteLogPage siteLog = new AdminSiteLogPage(homePage);
            siteLog.ReportTypeSelectList.Select("User Registrations By Country");
            siteLog.DisplayReportLink.Click();
            Assert.IsTrue(ieInstance.Frames.Count == 11, "There are " + ieInstance.Frames.Count + " Frames.");
        }


        [Test]
        public void DNN_12678_ProfilesProperties_Not_HtmlEncoding_Data()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add a user
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1500);

            //Act
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).Click();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.ManageProfileLink.Click();
            profilePage.PostalCodeField.Value = "<i>POSTALCODE</i>";
            userPage.UpdateLink.Click();
            System.Threading.Thread.Sleep(2500);

            //Assert
            profilePage.ManageProfileLink.Click();
            Assert.IsTrue(profilePage.PostalCodeField.Text.Equals("<i>POSTALCODE</i>"));
            ieInstance.GoTo(SiteURL + "/home.aspx");
            //Login as the new user
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            //Navigate to the users profile page 
            loginPage.RegisterLink.Click();
            System.Threading.Thread.Sleep(5000);
            Assert.IsTrue(profilePage.ProfileAddressDiv.Divs[2].Text.Contains("<i>POSTALCODE</i>"));
        }

        [Test]
        public void DNN_12679_Fix_issue_Where_Profile_Properties_Could_Be_Exposed_Under_Certain_Conditions()
        {
            //Arrange
            SetUpTestForInstall();
            RunAutoInstall();
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act
            //Add a user
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1500);

            //Log in as User
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);

            //Navigate to their profile, take note of the URL
            loginPage.RegisterLink.Click();
            String userProfileLink = ieInstance.Url;
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.EditProfileLink.Click();
            Span radioButtonSpan;
            //Set each radio button to Members Only
            foreach (TableRow row in profilePage.PropertiesTable.OwnTableRows)
            {
                radioButtonSpan = row.Span(Find.ById(s => s.EndsWith("vis")));
                //Members Only is the second radio button so the value of the radio button is '1'
                radioButtonSpan.RadioButton(Find.ByValue("1")).Checked = true;
            }
            //Add Content
            


        }

        #endregion

      


    }
}
